package com.example.wanglong.myoneapplication.activity;

import android.view.MotionEvent;
import android.view.View;
import android.view.ViewTreeObserver;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.ScrollView;

import com.example.wanglong.myoneapplication.R;
import com.example.wanglong.myoneapplication.adbanner.VisaImageCycleView;
import com.example.wanglong.myoneapplication.common.BaseActivity;

/**
 * Created by wang.long on 2016/4/14.
 */
public class TitleChange extends BaseActivity {



    private LinearLayout v;
    private ScrollView mScrollView;

    public static void init(){
         TitleChange titleChange=new TitleChange();
            titleChange.initData();
    }


    //初始化
    public void initData(){

        v =(LinearLayout) findViewById(R.id.visatitle);
        v.getBackground().setAlpha(0);

        //滑动title透明度变化
        initChangeTitle();


    }


    //滑动title透明度变化
    public void initChangeTitle(){
        mScrollView=(ScrollView) findViewById(R.id.scrollvisacontent);
        mScrollView.setOnTouchListener(new TouchListenerImpl());
        final ViewTreeObserver.OnScrollChangedListener listener = new ViewTreeObserver.OnScrollChangedListener() {
            @Override
            public void onScrollChanged() {
                System.out.println(mScrollView.getScrollY());
                int sy=mScrollView.getScrollY();
                if(sy>=0 && sy<=255){
                    v.getBackground().setAlpha(sy);
                } else if(sy>255){
                    v.getBackground().setAlpha(255);
                }
            }
        };
        ViewTreeObserver observer = mScrollView.getViewTreeObserver();
        observer.addOnScrollChangedListener(listener);
    }

    //监控touch事件title透明度变化
    private class TouchListenerImpl implements View.OnTouchListener {
        @Override
        public boolean onTouch(View view, MotionEvent motionEvent) {
            //System.out.println(view.getScrollY());
            int sy=view.getScrollY();
            if(sy>=0 && sy<=255){
                v.getBackground().setAlpha(view.getScrollY());
            } else if(sy>255){
                v.getBackground().setAlpha(255);
            }
            return false;
        }

    }

}
